Chronos Module

History

current version 1.3 - 31st May 2023

version date comment
1.0 09/Nov/2008 Original code
1.1 12/Jun/2011 Add function to DateTimeIsDefault
1.2 30/Mar/2018 date transformed to UTC in TimeDifference before computing difference
1.3 31/May/2023 new function GetDayOfWeek

License

license: GNU GPL http://www.gnu.org/licenses/

This file is part of

MOSAICO -- MOdular library for raSter bAsed hydrologIcal appliCatiOn.

Copyright (C) 2011 Giovanni Ravazzani

Code Description

Language: Fortran 90.

Software Standards: "European Standards for Writing and
Documenting Exchangeable Fortran 90 Code".

Module Description:

set of fortran routines to manage date and time. The module adhers to the International Standard ISO 8601 specifications. Date and time is expressed in the form YYYY-MM-DDThh:mm:ssTZD where:

YYYY = four-digit year

MM = two-digit month (01=January, etc.)

DD = two-digit day of month (01 through 31)

hh = two digits of hour (00 through 23) (am/pm NOT allowed)

mm = two digits of minute (00 through 59)

ss = two digits of second (00 through 59)

TZD = time zone designator (+hh:mm or -hh:mm)

A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is hh hours and mm minutes ahead of UTC (Coordinated Universal Time). A time zone offset of "-hh:mm" indicates that the date/time uses a local time zone which is hh hours and mm minutes behind UTC.

Example: 2007-03-05T01:00:00+02:00

This standard notation helps to avoid confusion in international communication caused by the many different national notations and increases the portability of computer user interfaces. In addition, these formats have several important advantages for computer usage compared to other traditional date and time notations.

References: http://www.w3.org/TR/NOTE-datetime

http://en.wikipedia.org/wiki/ISO_8601

http://www.probabilityof.com/iso/8601v2000.pdf



Variables

Type Visibility Attributes Name Initial
character(len=timeStringLength), public, parameter :: timeDefault = '0000-00-00T00:00:00+00:00'
character(len=timeStringLength), public :: timeString
integer, public, parameter :: timeStringLength = 25

Interfaces

public interface ASSIGNMENT( = )

  • private subroutine TimeToString(string, time)

    Converts the value of the current DateTime object to its equivalent string representation

    Arguments

    Type IntentOptional Attributes Name
    character(len=timeStringLength), intent(out) :: string
    type(DateTime), intent(in) :: time
  • private subroutine Parse(time, string)

    Converts the specified string representation of a date and time to its DateTime equivalent.

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(out) :: time
    character(len=timeStringLength), intent(in) :: string
  • private subroutine Copy(time2, time1)

    Create an exact copy of DateTime

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(out) :: time2
    type(DateTime), intent(in) :: time1

public interface OPERATOR ( + )

  • public function AddSeconds(time1, step) result(time2)

    Adds the specified number of seconds to the value of this instance. If number of seconds is a negative number, the amount is subtracted

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    integer, intent(in) :: step

    Return Value type(DateTime)

public interface OPERATOR ( - )

  • private function TimeDifference(time1, time2) result(seconds)

    calculate the difference in seconds between two date: time1 - time2

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    type(DateTime), intent(in) :: time2

    Return Value integer(kind=long)

public interface OPERATOR ( /= )

  • private function Inequality(time1, time2) result(isInequal)

    return true if time1 is different from time2

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    type(DateTime), intent(in) :: time2

    Return Value logical

public interface OPERATOR ( < )

  • private function LessThan(time1, time2) result(less)

    return true if time1 is less than time2

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    type(DateTime), intent(in) :: time2

    Return Value logical

public interface OPERATOR ( <= )

  • private function LessThanOrEqual(time1, time2) result(lessequal)

    return true if time1 is less than time2 or time1 is equal to time2

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    type(DateTime), intent(in) :: time2

    Return Value logical

public interface OPERATOR ( == )

  • private function Equality(time1, time2) result(isEqual)

    return true if time1 is equal to time2. Before comparison, dates are converted to UTC

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    type(DateTime), intent(in) :: time2

    Return Value logical

public interface OPERATOR ( > )

  • private function GreaterThan(time1, time2) result(greater)

    return true if time1 is greater than time2

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    type(DateTime), intent(in) :: time2

    Return Value logical

public interface OPERATOR ( >= )

  • private function GreaterThanOrEqual(time1, time2) result(greatequal)

    return true if time1 is greater than time2 or time1 is equal to time2

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time1
    type(DateTime), intent(in) :: time2

    Return Value logical


Derived Types

type, public ::  DateTime

Components

Type Visibility Attributes Name Initial
integer(kind=short), public :: TZhour
integer(kind=short), public :: TZminute
character(len=1), public :: TZsign
integer(kind=short), public :: day
integer(kind=short), public :: hour
integer(kind=short), public :: minute
integer(kind=short), public :: month
integer(kind=short), public :: second
integer(kind=short), public :: year

Functions

public function AddDays(time1, step) result(time2)

Adds the specified number of days to the value of this instance.

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
integer, intent(in) :: step

Return Value type(DateTime)

public function AddHours(time1, step) result(time2)

Adds the specified number of hours to the value of this instance.

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
integer, intent(in) :: step

Return Value type(DateTime)

public function AddMinutes(time1, step) result(time2)

Adds the specified number of minutes to the value of this instance.

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
integer, intent(in) :: step

Return Value type(DateTime)

public function AddSeconds(time1, step) result(time2)

Adds the specified number of seconds to the value of this instance. If number of seconds is a negative number, the amount is subtracted

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
integer, intent(in) :: step

Return Value type(DateTime)

public function DateTimeIsDefault(time) result(isDefault)

Check if datetime is set to default

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value logical

public function DayOfYear(time, leap) result(day)

Gets the day of the year represented by this instance. Returns 366 for leap years

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time
character(len=*), intent(in), optional :: leap

Return Value integer(kind=short)

public function GetDay(time) result(day)

Gets the day of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

public function GetDayOfWeek(time) result(day)

Gets the day of week (0 - 6) (Sunday to Saturday The formula is:

Read more…

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

returned value

public function GetHour(time) result(hour)

Gets the month of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

public function GetMinute(time) result(minute)

Gets the minute of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

public function GetMonth(time) result(month)

Gets the month of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

public function GetSecond(time) result(second)

Gets the second of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

public function GetTimeZone(time) result(timeZone)

Gets the string representing time zone of the datetime represented by this instance. Example: '+02:00'

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value character(len=6)

public function GetYear(time) result(year)

Gets the year of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

public function IsLeapYear(year) result(isLeap)

Returns true if the specified year is a leap year

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: year

Return Value logical

public function IsUTC(time) result(utc)

Returns true if datetime object is expressed in UTC

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value logical

public function Now() result(time)

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

Arguments

None

Return Value type(DateTime)

public function ToUTC(time1) result(time2)

Converts the value of the current DateTime object to Coordinated Universal Time (UTC).

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1

Return Value type(DateTime)

public function UtcNow() result(time)

Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

Arguments

None

Return Value type(DateTime)

private function DaysInMonth(month, year) result(days)

Returns the number of days in the specified month. It accounts for leap years

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: month
integer(kind=short), intent(in) :: year

Return Value integer(kind=short)

private function Equality(time1, time2) result(isEqual)

return true if time1 is equal to time2. Before comparison, dates are converted to UTC

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
type(DateTime), intent(in) :: time2

Return Value logical

private function GreaterThan(time1, time2) result(greater)

return true if time1 is greater than time2

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
type(DateTime), intent(in) :: time2

Return Value logical

private function GreaterThanOrEqual(time1, time2) result(greatequal)

return true if time1 is greater than time2 or time1 is equal to time2

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
type(DateTime), intent(in) :: time2

Return Value logical

private function Inequality(time1, time2) result(isInequal)

return true if time1 is different from time2

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
type(DateTime), intent(in) :: time2

Return Value logical

private function LessThan(time1, time2) result(less)

return true if time1 is less than time2

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
type(DateTime), intent(in) :: time2

Return Value logical

private function LessThanOrEqual(time1, time2) result(lessequal)

return true if time1 is less than time2 or time1 is equal to time2

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
type(DateTime), intent(in) :: time2

Return Value logical

private function SecondOfYear(time) result(second)

Gets the second of the year represented by this instance.

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

private function SecondsToEnd(time) result(second)

Gets the second to the end of the year represented by this instance.

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

Return Value integer(kind=short)

private function TimeDifference(time1, time2) result(seconds)

calculate the difference in seconds between two date: time1 - time2

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time1
type(DateTime), intent(in) :: time2

Return Value integer(kind=long)


Subroutines

public subroutine SetDay(day, time)

Set the day of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: day
type(DateTime), intent(out) :: time

public subroutine SetHour(hour, time)

Set the hour of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: hour
type(DateTime), intent(out) :: time

public subroutine SetMinute(minute, time)

Set the minute of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: minute
type(DateTime), intent(out) :: time

public subroutine SetMonth(month, time)

Set the month of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: month
type(DateTime), intent(out) :: time

public subroutine SetSecond(second, time)

Set the second of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: second
type(DateTime), intent(out) :: time

public subroutine SetTimeZone(timeZone, time)

Set the timezone of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: timeZone
type(DateTime), intent(out) :: time

public subroutine SetYear(year, time)

Set the year of the datetime represented by this instance

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: year
type(DateTime), intent(out) :: time

private subroutine Copy(time2, time1)

Create an exact copy of DateTime

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(out) :: time2
type(DateTime), intent(in) :: time1

private subroutine DateCheck(time)

check that date do not contain errors.

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

private subroutine Parse(time, string)

Converts the specified string representation of a date and time to its DateTime equivalent.

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(out) :: time
character(len=timeStringLength), intent(in) :: string

private subroutine TimeToString(string, time)

Converts the value of the current DateTime object to its equivalent string representation

Arguments

Type IntentOptional Attributes Name
character(len=timeStringLength), intent(out) :: string
type(DateTime), intent(in) :: time